<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ include file="/common-app/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>项目征集查询</title>
<script type="text/javascript" src="${res}/js/proposal/irisPrpPrepare.js"></script>
<script type="text/javascript" src="${res_app}/js/app/proposal/irisPrpPrepare.js"></script>
</head>

<body>
	<input type="hidden" id="childDiv" class="thickbox" />
	<form method="post" id="mainForm">
		<input type="hidden" id="prpCodes" name="prpCodes" value="" /> <input type="hidden" id="type" name="type" value="" />
	</form>

	<div class="soBox">
		<div class="detail ico_search">
			<table>
				<tr>
					<td rowspan="2">
						<strong>检索条件：</strong>
					</td>
					<td>
						<cpt:search key="prjCollections_search" repeatColumn="3" displayCount="6" leftStyle="width:80px"></cpt:search>
						<%-- 						<cpt:search key="prpApprove_search2"  repeatColumn="3" displayCount="6" leftStyle="width:80px"></cpt:search> --%>
					</td>
				</tr>
				<tr>
					<td>
						<div class="clear_h10"></div>
						<input type='button' id='searchBt' class="button_an" value='查询' />
					</td>
				</tr>
			</table>
		</div>
	</div>
	<div class="clear_h10"></div>
	<div>
		<div id='TopBarMnt'></div>
		<table id='dataGrid'></table>
		<div id='dataBar'></div>
	</div>
	<iframe id="ifile" style="display: none"></iframe>
	<form action="${ctx}/prpapprove/export_excel" method="post" id="exportExcel">
		<input type="hidden" name="searchString" id="searchString" value="" /> <input type="hidden" name="sidx" id="sortItem"
			value="" /> <input type="hidden" name="sord" id="sortType" value="" /> <input name="grantCnameKJ" type="hidden"
			id="grantCnameKJ">
	</form>
	<script type="text/javascript">
		var irisGrid = new IrisGrid("dataGrid", "dataBar", 'TopBarMnt');
		var prcWin = new progressWin("${res}");//初始化遮罩层
		function showApproveDialog(type) {
			var prpCodes = "";

			$(":checkbox:checked").each(
					function() {
						var rowId = $(this).attr("id");
						var id = rowId.substring(rowId.lastIndexOf("_") + 1,
								rowId.length);//取出grid中需要的id
						if (id != null && id != "" && $.isNumeric(id))
							prpCodes = prpCodes + id + ",";
					});

			if (prpCodes == "") {
				scmError("请选择一条记录");
				return false;
			}
			if (type == "approve") {

				var prpnum = prpCodes.split(",").length - 1;
				$("#prpCodes").val(prpCodes);
				$("#type").val(type);
				var options = {
					beforeSubmit : function() {
						prcWin.openWin();//打开遮罩层
						$("#approve").attr("disabled", true);
					}, // 表单提交前的回调函数
					success : function(msg) {
						prcWin.closeWin();
						scmSuccess(msg);
						irisGrid.getGridDom().jqGrid("refresh", 0);//0是本页1是首页
						$("#approve").attr("disabled", false);
					},// 表单成功提交后的回调函数
					error : function() {
						scmError("操作失败,请联系系统管理员");
						prcWin.closeWin();
						$("#approve").attr("disabled", false);
					},
					url : "${ctx}/prpapprove/" + type
				};
				if (confirm("是否确认此" + prpnum + "份申请书?")) {
					$("#mainForm").ajaxSubmit(options);
				} else {
					return;
				}

			} else {
				var url = "${ctx}/prpapprove/openprpapprovedialog?prpCodes="
						+ prpCodes + "&type=" + type
						+ "&TB_iframe=true&height=220&width=400";
				var title = "申报审核意见（最多为500字）";
				showThickBox(url, title);
			}

		}

		function checkSelect() {
			var selectArray = irisGrid.getGridDom().jqGrid("getGridParam",
					'selarrrow');//获得选中行
			$("#approve").removeAttr("disabled");//去除该属性
			for ( var i = 0; i < selectArray.length; i++) {
				var status = irisGrid.getGridDom().jqGrid('getCell',
						selectArray[i], "13");
				var flagCan = irisGrid.getGridDom().jqGrid('getCell',
						selectArray[i], "14");
				if (status == '01' && flagCan == "0") {
					$("#approve").attr("disabled", "disabled");
					scmError("您所选择的这" + selectArray.length
							+ "份申请书中有部分申请书的正式PDF未生成，请在生成之后再选择该申请书进行确认操作");
				}
			}
		}

		function viewComment(des3Prpcode) {
			var url = "${ctx}/proposal/view/audit-comment-view?posCode="
					+ des3Prpcode + "&TB_iframe=true&height=390&width=720";
			var title = "审核意见";
			showThickBox(url, title);
		}

		function closeDialog() {
			tb_remove();
		}

		/** 表格初始化**/
		function buildGrid() {
			var columnAttrList = new Array();

			columnAttr = new ColumnAttr("建议名称", "zh_title", "zh_title", 7,
					"left", true);//表头，字段名，，，宽度比例，居左，是否需要表头排序
			columnAttrList.push(columnAttr);

			columnAttr = new ColumnAttr("年度", "stat_year", "stat_year", 5,
					"center", true);
			columnAttrList.push(columnAttr);

			columnAttr = new ColumnAttr("所属领域", "prj_category_value",
					"prj_category_value", 5, "left", true);
			columnAttrList.push(columnAttr);

			columnAttr = new ColumnAttr("合作形式", "cooperate_way_value",
					"cooperate_way_value", 5, "left", true);
			columnAttrList.push(columnAttr);

			columnAttr = new ColumnAttr("所处阶段", "state_in_value",
					"state_in_value", 5, "left", true);
			columnAttrList.push(columnAttr);
			columnAttr = new ColumnAttr("技术来源", "tech_source_value",
					"tech_source_value", 5, "left", true);
			columnAttrList.push(columnAttr);
			columnAttr = new ColumnAttr("实施年限", "imp_period_value",
					"imp_period_value", 5, "left", true);
			columnAttrList.push(columnAttr);

			columnAttr = new ColumnAttr("联系人", "contact_psn_cname",
					"contact_psn_cname", 5, "center", true);
			columnAttrList.push(columnAttr);

			columnAttr = new ColumnAttr("联系电话", "contact_tel", "contact_tel",
					5, "left", true);
			columnAttrList.push(columnAttr);

			columnAttr = new ColumnAttr("PDF", "pdf", "pdf", 4, "center", false);
			columnAttrList.push(columnAttr);

			/* columnAttr = new ColumnAttr("status", "status", "status", 3,
					"left", false, false, "text", true);
			columnAttrList.push(columnAttr);
			columnAttr = new ColumnAttr("flagCan", "flagCan", "flagCan", 3,
					"left", false, false, "text", true);
			columnAttrList.push(columnAttr);
			columnAttr = new ColumnAttr("grantCode", "grantCode", "grantCode",
					3, "left", false, false, "text", true);
			columnAttrList.push(columnAttr);
			columnAttr = new ColumnAttr("introPdfCode", "introPdfCode",
					"introPdfCode", 3, "left", false, false, "text", true);
			columnAttrList.push(columnAttr); */
			irisGrid.setColumnAttrs(columnAttrList);

			irisGrid.setUrl("${ctx}/prpapprove/list-prj-collections");//查询url
			irisGrid.setCaption("暂写");
			irisGrid
					.setDefaultSortName("NLSSORT(grant_name,'NLS_SORT = SCHINESE_PINYIN_M') asc,NLSSORT(org_name,'NLS_SORT = SCHINESE_PINYIN_M') asc,NLSSORT(psn_name,'NLS_SORT = SCHINESE_PINYIN_M') asc,NLSSORT(zh_title,'NLS_SORT = SCHINESE_PINYIN_M'),prp_no");//默认排序字段
			irisGrid.setDefaultSortorder("asc");
			irisGrid.setWidth(978);//整个表格宽度
// 			irisGrid.setCheckAble(true);//表格左边是否要复选框
			irisGrid.setCheckAble(false);//表格左边是否要复选框
			irisGrid.setShowRowIndex(true);//是否显示行号
			irisGrid.setCanExportExcel(true);
			irisGrid.setQueryBox('searchBt', 'prjCollections_search');//查询条件 按钮名，查询条件function_key
			irisGrid.onSelectAll = function(selectid, isSelect) {//全选事件
				checkSelect();
			}
			irisGrid.onSelectRow = function(selectid, isSelect) {//选择事件	
				checkSelect();
			}
			irisGrid.setLoadComplete(function() {
				irisGrid.attendQuery = true;
				var searchString = irisGrid.preDealOnQuery()['searchString'];
				$("#searchString").val(searchString);
				$("#sortItem").val(
						irisGrid.getGridDom()
								.jqGrid("getGridParam", 'sortname'));
				$("#sortType").val(
						irisGrid.getGridDom().jqGrid("getGridParam",
								'sortorder'));
				//当前显示多少条
				var length = $("#dataGrid").getDataIDs().length;
				if (length > 0) {//当资助类别不为空且 当前页数据大于0时，显示按钮
					$("#exportPrjDetailG").show();
				} else {
					$("#exportPrjDetailG").hide();
				}
			});
			irisGrid.build();
		}
		jQuery(function() {
			setStatus();
			buildGrid();
			$("div[class*='ui-jqgrid-bdiv']").css("overflow", "hidden");
			$("#TopBarMnt").css("width", "971px");
			/*$("#dataGrid_toppager").css("display","none");
			$("#dataBar").css("display","none");
			$("a[class*='HeaderButton']").click(function(){
			$("#dataGrid_toppager").css("display","none");
			}); */
			$("#cb_dataGrid")
					.click(
							function() {
								var checked = $(this).attr("checked");
								if (checked == "checked") {
									$("#dataGrid").find(
											"td input[type='checkbox']").attr(
											"checked", "checked");
									$("#dataGrid")
											.find("tr[class*='jqgrow']")
											.each(
													function() {
														if ($(this)
																.find(
																		"td input[type='checkbox']").length <= 0) {
															$(this)
																	.removeClass(
																			"ui-state-highlight");
														}
													});

								} else {
									$("#dataGrid").find(
											"td input[type='checkbox']").attr(
											"checked", false);
								}
							});
			var index = 0;
			var stat_year = "";
			$("dl[id='stat_year']").find("a[class='c_item_checked']").each(
					function() {
						stat_year = $(this).prev().val();
						index++;
					});
			if (index > 1)
				stat_year = "0";
			$("#research,#research_img,#research_tree_img").unbind("click")
					.removeAttr("onclick");
			$("#research,#research_img,#research_tree_img").bind(
					"click",
					function() {

						show_research("research", {
							"locale" : "zh_CN",
							"key" : "technosphere",
							"cacheable" : "false",
							"sqlParamVal" : "{'grant_code':'"
									+ $("#grantCname_hideId").val()
									+ "','stat_year':'" + stat_year + "'}"
						});
					});
			$("#domain,#domain_img,#domain_tree_img").unbind("click")
					.removeAttr("onclick");
			$("#domain,#domain_img,#domain_tree_img").bind(
					"click",
					function() {
						show_domain("domain", {
							"locale" : "zh_CN",
							"key" : "domain1",
							"cacheable" : "false",
							"sqlParamVal" : "{'grant_code':'"
									+ $("#grantCname_hideId").val()
									+ "','stat_year':'" + stat_year
									+ "','researchCode':'"
									+ $("#research_hideId").val() + "'}"
						});
					});

		});

		//导出excel方法
		var exportPrjDetail = function() {
			var grantCode = $("#grant_code").val();
			if (grantCode == '916') {
				//科学技术奖导出
				showReportKxjsjDialog();
			} else {
				$("#exportExcel").submit();
			}
		};

		var getSelOpt = function() {
			var g = "";
			$("input:checkbox[id^='jqg_dataGrid_']").each(function(i, obj) {
				if (obj.checked) {
					g += "," + obj.id.replace("jqg_dataGrid_", "");
				}
			});
			if (g != "") {
				g = g.substring(1);
			}
			return g;
		};

		//打包下载pdf
		var exportPdf = function() {

			var keyCodes = getSelOpt();
			var count = keyCodes.split(",").length;
			if (count > 50) {
				scmWarn("请不要选择超过50个项目！", null, 2000);
				return false;
			}
			if (keyCodes == "") {
				scmWarn("请选择要下载pdf的项目！", null, 2000);
				return false;
			}
			scmSuccess("正在下载……请稍侯…", null, 4000);
			var url = "${ctx}" + "/proposal/getintrozip?type=pdf&keyCodeStr="
					+ encodeURIComponent(keyCodes);
			$("#ifile").attr("src", url);
			//location ="${ctx}"+ "/proposal/getintrozip?type=pdf&keyCodeStr="+encodeURIComponent(keyCodes);
			return false;
		}

		//批量下载简介表
		var exportIntro = function() {
			var keyCodes = getSelOpt();
			var flag = getSelIntroPdfCode();
			if (!flag) {
				scmWarn("您选择了没有简介表的项目，请重新选择！", null, 2000);
				return false;
			}
			if (keyCodes == "") {
				scmWarn("请选择要下载简介的项目！", null, 2000);
				return false;
			}
			scmSuccess("正在下载……请稍侯…", null, 4000);
			location = "${ctx}"
					+ "/proposal/getintrozip?type=introPdf&keyCodeStr="
					+ encodeURIComponent(keyCodes);
			return false;
		}

		var getSelIntroPdfCode = function() {
			var flag = true;
			$("input:checkbox[id^='jqg_dataGrid_']").each(
					function(i, obj) {
						if (obj.checked) {
							var introPdfCode = $(obj).parent().parent().find(
									"input:hidden[id^='introPdfCode_']").val();
							if (introPdfCode == "" || introPdfCode == null) {
								flag = false;
							}
						}
					});
			return flag;

		}

		function setStatus() {
			if ('${param.prpstatus}' != '') {
				$("#prpstatus option[value='${param.prpstatus}']").attr(
						"selected", "selected");
				//$("#prpstatus option[value='1']").attr("selected", "selected"); 
			}
		}
		/** 显示工作进度 */
		function showPrjProgress(keyCode, progressCode) {
			var url = ctx + "/prpapprove/showPrjProgress";
			url = url + "?keyCodeStr=" + keyCode + "&progressCode="
					+ progressCode;
			url = url + "&TB_iframe=true&height=500&width=700";
			tb_show("工作进度", url, false);
		}
		/**查看单位信息*/
		function orgInfoView(orgCode) {
			//$("#orgCode").val(orgCode);
			//$("#mainForm").submit();
			tb_show("查看单位信息",
					"${ctx}/orgmanage/verifyorg/org-info-view?orgCode="
							+ orgCode + "&TB_iframe=true&height=460&width=950",
					false);
		}

		/* function showReportDialog(){
			var searchString=jQuery('#dataGrid').jqGrid('getGridParam','postData')['searchString'];
			if($("#grant_code").val() == '' || $("#grant_code").val()  == undefined)
			{
				tb_show("打印汇总表","${ctx}/prpapprove/list-for-report"+"?searchString="+encodeURIComponent(searchString)+"&TB_iframe=true&height=460&width=1024", false);
			}else{
				//先封装数据
				var urlStr = "";
				var criteria_key = $("#_dyn_panel").attr("functionkey");
				var queryTableObj = $("#" + criteria_key + " *[id='_dyn_panel']");
				var querySels = [];
				$("[id^='_dyn_criteria'][id$='_field']", queryTableObj).each(
						function() {
							querySels.push($(this).attr('id'));
						});
				var querySelIdCrowd = querySels;
				
				var queryKVStr = '';
				for ( var i = 0; i < querySelIdCrowd.length; i++) {
					var selId = querySelIdCrowd[i];
					var queryId = $("#"+criteria_key).find('#' + selId).val();
					var destContral = $("#"+criteria_key).find('#' + queryId, $('#' + selId).parent().next());
					var queryValue = destContral.val();
					var fieldname = destContral.attr("name");
					var queryCellValue = $.trim(queryValue);
					if(i != querySelIdCrowd.length-1){
						urlStr = urlStr +fieldname+":"+queryCellValue+"[tear]";
					}else{
						urlStr = urlStr +fieldname+":"+queryCellValue;
					}
				}			
				tb_show("打印汇总表","${ctx}/prpapprove/list-for-report1"+"?searchString="+encodeURIComponent(urlStr)+"&TB_iframe=true&height=460&width=1024", false);
				
			}
		}
		 */
		function showReportKxjsjDialog() {
			//得到页面查询条件
			var searchString = jQuery('#dataGrid').jqGrid('getGridParam',
					'postData')['searchString'];
			if ($("#grant_code").val() == ''
					|| $("#grant_code").val() == undefined) {
				alert("项目类别不能为空");
			} else if ($("#grant_code").val() != '916') {
				alert("请选择科学技术奖项目");
			} else {
				//先封装数据
				//拼接查询条件的值,形如k,v;多个值之间使用[tear]隔开,当new一个PageHanlder的时候,会自动将值进行封装到ConditionContainer中
				var urlStr = "";
				var criteria_key = $("#_dyn_panel").attr("functionkey");
				var queryTableObj = $("#" + criteria_key
						+ " *[id='_dyn_panel']");
				var querySels = [];
				$("[id^='_dyn_criteria'][id$='_field']", queryTableObj).each(
						function() {
							querySels.push($(this).attr('id'));
						});
				var querySelIdCrowd = querySels;

				var queryKVStr = '';
				for ( var i = 0; i < querySelIdCrowd.length; i++) {
					var selId = querySelIdCrowd[i];
					var queryId = $("#" + criteria_key).find('#' + selId).val();
					var destContral = $("#" + criteria_key).find('#' + queryId,
							$('#' + selId).parent().next());
					var queryValue = destContral.val();
					var fieldname = destContral.attr("name");
					var queryCellValue = $.trim(queryValue);
					if (i != querySelIdCrowd.length - 1) {
						urlStr = urlStr + fieldname + ":" + queryCellValue
								+ "[tear]";
					} else {
						urlStr = urlStr + fieldname + ":" + queryCellValue;
					}
				}

				var statYear = $("#stat_year").find("option:selected").text();

				//type表示导出类型,与数据库表proposal_sl_report中的rpt_no对应,当type为空时默认设置为1,导出科学技术奖申请书信息时设置type为2
				tb_show(
						"导出科学技术奖项目信息清单",
						ctx
								+ "/prpapprove/list-for-report1-kxjsj?searchString="
								+ encodeURIComponent(urlStr)
								+ "&statYear="
								+ statYear
								+ "&rpt_no_type=2&TB_iframe=true&height=460&width=1024",
						false);

			}
		}
		function initSubjectTreeValueExp2(treeId, treeNode) {
			if (treeId == "grant") {
				$("#research").val("");
				$("#research_hideId").val("");
				$("#research_hideName").val("");
				$("#researchCname_hideId").val("");
				$("#researchCname").val("");
				$("#research_value").val("");
				$("#domain").val("");
				$("#domain_hideId").val("");
				$("#domain_hideName").val("");
				$("#domainCname_hideId").val("");
				$("#domainCname").val("");
				$("#domain_value").val("");
				$("#grant_code").val(treeNode.id);
				$("#grantCnameKJ").val(treeNode.name);
			} else if (treeId == "research") {
				$("#domain").val("");
				$("#domain_hideId").val("");
				$("#domain_hideName").val("");
				$("#domainCname_hideId").val("");
				$("#domainCname").val("");
				$("#domain_value").val("");
				$("#research_value").val(treeNode.id);
			} else if (treeId == "domain") {
				$("#domain_value").val(treeNode.id);
			}
			$("#" + treeId).parents("td").find(
					"[name$='" + treeId + "Cname_hideId'],[id$='" + treeId
							+ "Cname_hideId']").val(treeNode.id);
			var str = treeNode.name;
			var obj = treeNode.parentNode;
			while (obj != null) {
				str = obj.name + "-" + str;
				obj = obj.parentNode;
			}
			$("#" + treeId).parents("td")
					.find(
							"[name$='" + treeId + "Cname'],[id$='" + treeId
									+ "Cname']").val(
							str.substring(str.indexOf("-") + 1));
		}
		//覆盖函数
		function initSubjectTreeValueExp(treeId, treeNode) {
			if (treeId == "grant") {
				$("#research").val("");
				$("#research_hideId").val("");
				$("#research_hideName").val("");
				$("#researchCname_hideId").val("");
				$("#researchCname").val("");
				$("#research_value").val("");
				$("#domain").val("");
				$("#domain_hideId").val("");
				$("#domain_hideName").val("");
				$("#domainCname_hideId").val("");
				$("#domainCname").val("");
				$("#domain_value").val("");
				$("#grant_code").val(treeNode.id);
			} else if (treeId == "research") {
				$("#domain").val("");
				$("#domain_hideId").val("");
				$("#domain_hideName").val("");
				$("#domainCname_hideId").val("");
				$("#domainCname").val("");
				$("#domain_value").val("");
				$("#research_value").val(treeNode.id);
			} else if (treeId == "domain") {
				$("#domain_value").val(treeNode.id);
			}
			$("#" + treeId).parents("td").find(
					"[name$='" + treeId + "Cname_hideId'],[id$='" + treeId
							+ "Cname_hideId']").val(treeNode.id);
			$("#" + treeId).parents("td")
					.find(
							"[name$='" + treeId + "Cname'],[id$='" + treeId
									+ "Cname']").val(
							treeNode.name
									.substring(treeNode.name.indexOf(".") + 1));
		}
	</script>
</body>
</html>